﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using App.Core.Extensions;
using App.Data;
using System.Text;

public partial class UserControls_AlphabeticControl : BaseUserControl
{
    private List<String> _Letters = new List<string>()
    {
        "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S",
        "T", "U", "V", "W", "X", "Y", "Z"
    };
    public String URLFormat { get; set; }
    public String CurrentLetter { get; set; }
    protected void Page_Load(object sender, EventArgs e)
    {
        BindControl();
    }
    protected void BindControl()
    {
        if (this.URLFormat.IsNullOrEmpty())
            throw new ArgumentException("URLFormat can not be blank.");
        else
        {
            StringBuilder sb = new StringBuilder();
            int i = 0;
            foreach (String letter in _Letters)
            {
                if (String.Compare(letter, CurrentLetter, true) == 0)
                    sb.AppendFormat("{0}", letter);
                else
                    sb.AppendFormat("<a href=\"{0}\">{1}</a>", GetFormattedUrl(letter), letter);
                i++;
                if (i < 26)
                    sb.Append(" | ");
            }
            ltrControls.Text = sb.ToString();
        }
    }

    protected String GetFormattedUrl(String letter)
    {
        return String.Format(this.URLFormat, letter);
    }
}